<?php

class Expert extends CActiveRecord
{
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	public function tableName()
	{
		//return 'tbl_expert';
        return '{{expert}}';
	}

	public function rules()
	{
		return array(
			array('first_name', 'required'),
			array('first_name, last_name, middle_name', 'length', 'max'=>100),
			array('rating_id, category_id', 'length', 'max'=>10),
			array('avatar_small, avatar_big', 'length', 'max'=>255),
			array('about', 'safe'),
			array('id, first_name, last_name, middle_name, rating_id, category_id, avatar_small, avatar_big, about', 'safe', 'on'=>'search'),
		);
	}

	public function relations()
	{
		return array(
			'rating' => array(self::BELONGS_TO, 'Rating', 'rating_id'),
			'category' => array(self::BELONGS_TO, 'Category', 'category_id'),
		);
	}

	public function behaviors()
	{
		return array('CAdvancedArBehavior',
				array('class' => 'ext.CAdvancedArBehavior')
				);
	}

	public function attributeLabels()
	{
		return array(
			'id' => Yii::t('app', 'ID'),
			'first_name' => Yii::t('app', 'First Name'),
			'last_name' => Yii::t('app', 'Last Name'),
			'middle_name' => Yii::t('app', 'Middle Name'),
			'rating_id' => Yii::t('app', 'Rating'),
			'category_id' => Yii::t('app', 'Category'),
			'avatar_small' => Yii::t('app', 'Avatar Small'),
			'avatar_big' => Yii::t('app', 'Avatar Big'),
			'about' => Yii::t('app', 'About'),
		);
	}

	public function search()
	{
		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);

		$criteria->compare('first_name',$this->first_name,true);

		$criteria->compare('last_name',$this->last_name,true);

		$criteria->compare('middle_name',$this->middle_name,true);

		$criteria->compare('rating_id',$this->rating_id,true);

		$criteria->compare('category_id',$this->category_id,true);

		$criteria->compare('avatar_small',$this->avatar_small,true);

		$criteria->compare('avatar_big',$this->avatar_big,true);

		$criteria->compare('about',$this->about,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}
